home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / BYT2HEX.PRG < prev    next >
Text File  |  1991-08-15  |  2KB  |  82 lines

  1. /*
  2.  * File......: BYT2HEX.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:03:00  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/byt2hex.prv  $
  7.  * 
  8.  * This is an original work by Forest Belt and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/byt2hex.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:03:00   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:51:10   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:00:48   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_BYT2HEX()
  31.  *  $CATEGORY$
  32.  *     Conversion
  33.  *  $ONELINER$
  34.  *     Convert byte to hexadecimal version of its binary value
  35.  *  $SYNTAX$
  36.  *     FT_BYT2HEX( cByte ) -> cHexValue
  37.  *  $ARGUMENTS$
  38.  *     <cByte> is the byte to convert.
  39.  *  $RETURNS$
  40.  *     Three-character string, consisting of two digits of hexadecimal
  41.  *     notation and letter 'h' to signify hex.  Returns NIL if parameters are
  42.  *     faulty.
  43.  *  $DESCRIPTION$
  44.  *     Can be used to show results of bit manipulation, both before and after.
  45.  *
  46.  *     This function is presented to illustrate that bit-wise operations
  47.  *     are possible with Clipper code.  For greater speed, write .C or
  48.  *     .ASM versions and use the Clipper Extend system.
  49.  *  $EXAMPLES$
  50.  *     These three code lines perform a bitwise AND on bytes with values of
  51.  *     CHR(20) and CHR(36), and deliver the result as a string in hexadecimal
  52.  *     format, using 'h' to signify hexadecimal.
  53.  *
  54.  *          ? FT_BYT2HEX(CHR(20))         // byte1: '14h'
  55.  *          ? FT_BYT2HEX(CHR(36))         // byte2: '24h'
  56.  *
  57.  *          ? FT_BYT2HEX(FT_BYTEAND(CHR(20), CHR(36)))
  58.  *                             // result: '04h'
  59.  *
  60.  *     For a demonstration of Clipper bit manipulations, compile and
  61.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  62.  *  $SEEALSO$
  63.  *     FT_BYT2BIT()
  64.  *  $END$
  65.  */
  66.  
  67. FUNCTION FT_BYT2HEX(cByte)
  68.  
  69.   local cHexTable := "0123456789ABCDEF"
  70.   local xHexString
  71.  
  72.   if valtype(cByte) != "C"
  73.      xHexString := NIL
  74.   else
  75.      xHexString := substr(cHexTable, int(asc(cByte) / 16) + 1, 1) ;
  76.                  + substr(cHexTable, int(asc(cByte) % 16) + 1, 1) ;
  77.                  + "h"
  78.   endif
  79.  
  80. RETURN xHexString
  81.  
  82.